$(function() {
	// 路径配置
	require.config({
		paths: {
			echarts: "../js/echarts/build/dist"
		}
	});
	drawCharts();
	drawChart();
});


function drawCharts(){
	// 使用
require(
	[
		'echarts', // 代指echarts设置的路径，即'../resource/build/dist'
'echarts/theme/macarons', //主题
'echarts/chart/bar', // 使用柱状图就加载bar模块，按需加载,引入bar.js
'echarts/chart/line',// 加载折线图,引入line.js文件, 按需加载
'echarts/chart/pie',// 加载饼状图,引入pie.js文件, 按需加载
'echarts/chart/funnel',// 加载漏斗图,引入funnel.js文件, 按需加载,
'echarts/chart/map',// 加载地图,引入funnel.js文件, 按需加载,
'echarts/chart/force'// 加载地图,引入force.js文件, 按需加载,
	],
	function(ec) {
		// 基于准备好的dom，初始化echarts图表
		var myChart = ec.init(document.getElementById('main1'));

		option = {
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data: ['最高', '最低']
			},
			toolbox: {
				show: true,
				feature: {
					mark: {
						show: true
					},
					dataView: {
						readOnly: false
					},
					magicType: {
						show: true,
						type: ['line', 'bar', 'stack', 'tiled']
					},
					restore: {
						show: true
					},
					saveAsImage: {
						show: true
					}
				}
			},
			calculable: true,
			dataZoom: {
				show: true,
				realtime: true,
				start: 40,
				end: 60
			},
			xAxis: [{
				type: 'category',
				boundaryGap: true,
				data: function() {
					var list = [];
					for(var i = 1; i <= 30; i++) {
						list.push('2013-03-' + i);
					}
					return list;
				}()
			}],
			yAxis: [{
				type: 'value'
			}],
			series: [{
				name: '最高',
				type: 'line',
				data: function() {
					var list = [];
					for(var i = 1; i <= 30; i++) {
						list.push(Math.round(Math.random() * 30) + 30);
					}
					return list;
				}()
			}, {
				name: '最低',
				type: 'bar',
				data: function() {

					var list = [];
					for(var i = 1; i <= 30; i++) {
						list.push(Math.round(Math.random() * 10));
					}
					return list;
				}()
			}]
		};

		// 为echarts对象加载数据 
		myChart.setOption(option);

		var ecConfig = require('echarts/config');

		function eConsole(param) {
			var mes = '【' + param.type + '】';
			if(typeof param.seriesIndex != 'undefined') {
				mes += '  seriesIndex : ' + param.seriesIndex;
				mes += '  dataIndex : ' + param.dataIndex;
			}
			if(param.type == 'click') {
				alert(param.name);
				document.getElementById('hover-console').innerHTML = 'Event Console : ' + param.name;
			} else {
				document.getElementById('console').innerHTML = mes;
			}
			console.log(param);
		}
		/*
		// -------全局通用
		REFRESH: 'refresh',
		RESTORE: 'restore',
		RESIZE: 'resize',
		CLICK: 'click',
		DBLCLICK: 'dblclick',
		HOVER: 'hover',
		MOUSEOUT: 'mouseout',
		// -------业务交互逻辑
		DATA_CHANGED: 'dataChanged',
		DATA_ZOOM: 'dataZoom',
		DATA_RANGE: 'dataRange',
		DATA_RANGE_HOVERLINK: 'dataRangeHoverLink',
		LEGEND_SELECTED: 'legendSelected',
		LEGEND_HOVERLINK: 'legendHoverLink',
		MAP_SELECTED: 'mapSelected',
		PIE_SELECTED: 'pieSelected',
		MAGIC_TYPE_CHANGED: 'magicTypeChanged',
		DATA_VIEW_CHANGED: 'dataViewChanged',
		TIMELINE_CHANGED: 'timelineChanged',
		MAP_ROAM: 'mapRoam',
		*/
		myChart.on(ecConfig.EVENT.CLICK, eConsole);
		myChart.on(ecConfig.EVENT.DBLCLICK, eConsole);
		//myChart.on(ecConfig.EVENT.HOVER, eConsole);
		myChart.on(ecConfig.EVENT.DATA_ZOOM, eConsole);
		myChart.on(ecConfig.EVENT.LEGEND_SELECTED, eConsole);
		myChart.on(ecConfig.EVENT.MAGIC_TYPE_CHANGED, eConsole);
		myChart.on(ecConfig.EVENT.DATA_VIEW_CHANGED, eConsole);
	}
)
}


function drawChart(){
	require(
            [
                'echarts', //代指echarts设置的路径，即'../resource/build/dist'
                'echarts/theme/macarons',
                'echarts/chart/bar', // 使用柱状图就加载bar模块，按需加载,引入bar.js
                'echarts/chart/line',//加载折线图,引入line.js文件, 按需加载
                
            ],
            function (ec,theme) {
                // 基于准备好的dom，初始化echarts图表
                //var test1=${requestScope.ss3};
	            //var data1=eval(test1);
	            // data1=data1[0];
                var myChart = ec.init(document.getElementById('main2'),theme); 
                 //var  option=data1;
               var option = {
                	    title : {
                    text: '未来一周气温变化',
                    subtext: '纯属虚构'
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['最高气温','最低气温']
                },
                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: false},
                        magicType : {show: true, type: ['bar','line']},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        //boundaryGap : false,
                        data : ['周一','周二','周三','周四','周五','周六','周日']
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                         axisLabel : {
                            formatter: '{value} °C'
                        } 
                    }
                ],
                series : [
                    {
                        name:'最高气温',
                        type:'line',
                        data:[11, 11, 15, 13, 12, 13, 10],
                         markPoint : {
                            data : [
                                {type : 'max', name: '最大值'},
                                {type : 'min', name: '最小值'}
                            ]
                        },
                        markLine : {
                            data : [
                                {type : 'average', name: '平均值'}
                            ]
                        } 
                    },
                    {
                        name:'最低气温',
                        type:'line',
                        data:[1, -2, 2, 5, 3, 2, 0],
                      markPoint : {
                            data : [
                                {name : '周最低', value : -2, xAxis: 1, yAxis: -1.5}
                            ]
                        },
                        markLine : {
                            data : [
                                {type : 'average', name : '平均值'}
                            ]
                        } 
                    }
                ]
            }; 

                // 为echarts对象加载数据 
                myChart.setOption(option,true); 
            }
        );
}